﻿using MediatR;
using Trace.Infrastructure.Repository;
using Trace.WebApi.Commands;

namespace Trace.WebApi.CommandHandler
{
    public class ShipmentsHZTracetCommandHandler : IRequestHandler<ShipmentsHZTracetCommands, int>
    {
        private readonly IRepository<Contract.Domain.Contract> _repository;

        public ShipmentsHZTracetCommandHandler(IRepository<Contract.Domain.Contract> repository)
        {
            _repository = repository;
        }

        public async Task<int> Handle(ShipmentsHZTracetCommands request, CancellationToken cancellationToken)
        {
            var info = await _repository.GetAsync(x => x.ContractNumber.Equals(request.ContractNumber));
            info.State = 1;
            info.UpdateDate = DateTime.Now;
            var ind = await _repository.UpdateAsync(info);
            return ind;
        }
    }
}
